package com.spremoteservice.android;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

public class Connector {
	public String siteUrl;
	public String userName;
	public String password;
	public String appId;
	private static Connector _instance;
	
	public Connector(String siteUrl, String userName, String password){
		this.siteUrl = siteUrl;
		this.userName = userName;
		this.password = password;
		_instance = this;
	}
	
	public static Connector GetInstance(){
		return _instance;
	}
	
	public ListViewSPObject GetWeb(String siteUrl) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		WebsService websService = new WebsService(siteUrl, userName, password);
		return websService.GetWeb();
	}
	
	public List<ListViewSPObject> GetListCollection(String siteUrl) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		ListsService listsService = new ListsService(siteUrl, userName, password);
		return listsService.GetListCollection();
	}
	
	public List<ListViewSPObject> GetFolderCollection(String siteUrl, String libName, String libId, String libPath) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		ListsService listsService = new ListsService(siteUrl, userName, password);
		return listsService.GetFolderCollection(libName, libId, libPath);
		
	}

	public List<ListViewSPObject> GetDocumentCollection(String siteUrl, String libName, String libId, String libPath) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		ListsService listsService = new ListsService(siteUrl, userName, password);
		return listsService.GetDocumentCollection(libName, libId, libPath);
		
	}
	
	public Boolean ConnectTo(String appId) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		RemoteService remoteService = new RemoteService(siteUrl, userName, password);
		if(remoteService.ConnectTo(appId)){
			this.appId = appId;
			return true;
		}else{
			return false;
		}
	}

	public Boolean OpenFile(String siteUrl, String filePath) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		RemoteService remoteService = new RemoteService(siteUrl, userName, password);
		if(remoteService.OpenFile(appId, siteUrl, filePath)){
			return true;
		}else{
			return false;
		}
	}
	public Boolean PageDown() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		RemoteService remoteService = new RemoteService(siteUrl, userName, password);
		if(remoteService.PageDown(appId)){
			return true;
		}else{
			return false;
		}
	}
	public Boolean PageUp() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		RemoteService remoteService = new RemoteService(siteUrl, userName, password);
		if(remoteService.PageUp(appId)){
			return true;
		}else{
			return false;
		}
	}
	public Boolean CloseFile() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException{
		RemoteService remoteService = new RemoteService(siteUrl, userName, password);
		if(remoteService.CloseFile(appId)){
			return true;
		}else{
			return false;
		}
	}
}
